package com.uchengwang.ui.cm_ui.uu.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.uu.bean.NoticeBean;
import com.uchengwang.ui.utils.DateUtil;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/11/30.
 */

public class MyNoticeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context context;
    private List<NoticeBean> list = new ArrayList<>();//普通用户反馈
    public MyNoticeAdapter(Context context){
        this.context = context;
    }

    public void setData(List<NoticeBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public List<NoticeBean> getData(){
        return list;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_system_view, parent, false);
        return new NoticeVH(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
        MyNoticeAdapter.NoticeVH holder = (NoticeVH) h;

        NoticeBean bean = list.get(position);

        holder.time.setText(DateUtil.getDateUtil().getTimeStringDate(bean.getCreateTime()));
        String response = bean.getMessage();

        holder.content.setText(response);

        ImageManager.getInstance().loadImage(context, holder.head, R.mipmap.uchenglogo, ImageManager.ImageType.CIRCLE);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class NoticeVH extends RecyclerView.ViewHolder{
        private View itemView;
        private TextView time, content;
        private ImageView head;

        public NoticeVH(View view) {
            super(view);

            AutoUtils.autoSize(view);
            itemView = view;

            time = (TextView) view.findViewById(R.id.system_time);
            content = (TextView) view.findViewById(R.id.system_content);
            head = (ImageView) view.findViewById(R.id.system_head);
        }
    }
}
